package com.job.liushuang.HomeWork0720;

import java.util.*;

/**
 * @author Liushuang
 * @version 1.0
 * @since 2022-07-20 19:13:33
 */
public class MapCount {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = sc.next();
        HashMap<Character,Integer> map = new LinkedHashMap<>();
        //遍历字符串
        for (int i = 0; i <str.length() ; i++) {//将字符串的字符赋值给变量key
            char key = str.charAt(i);
            if(map.containsKey(key)){//多次出现
                Integer value = map.get(key);
                value = value+1;
                map.put(key,value);
            }else{//出现一次
                map.put(key,1);
            }
        }
        //遍历map
        Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        for(Map.Entry<Character, Integer> entry : entries){
            Character key = entry.getKey();
            Integer  value = entry.getValue();
            System.out.println(key+"出现了："+value+"次");
        }
    }
}
